import com.fasterxml.jackson.databind.ObjectMapper;
import pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/json")
public class JsonServlet extends HttpServlet {
    public ObjectMapper mapper = new ObjectMapper();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        接收参数 req.getInputStream();
//        解析参数
//        mapper.writeValueAsString(); //把对象转成json串
        /**
         * readValues  把一个json串转出一个对象
         * 第一个参数是指: 把哪个字符串转出对象
         * 第二个参数: 转成什么样的对象
         */

        User user = mapper.readValue(req.getInputStream(), User.class);
        resp.getWriter().write("name:"+user.getName()+",age:"+user.getAge());

    }
}
